package tt.dz.dao.ext.charger;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;
import tt.dz.dao.base.OmsCommonDao;
import tt.dz.entity.charger.OmsChargerRate;
import tt.dz.entity.charger.OmsChargerRateEntity;
import tt.dz.entity.charger.OmsChargerRateKey;
import tt.dz.entity.exception.OmsDaoException;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

@Repository
public interface OmsChargerRateRepo extends JpaRepository<OmsChargerRateEntity, OmsChargerRateKey>
{
	List<OmsChargerRateEntity> findByRateSchema(Integer rateSchema);

	List<OmsChargerRateEntity> findByRateSchemaOrderBySerialNo(Integer rateSchema);

	@Query(" SELECT IFNULL(max(rate_schema), 0) + 1 FROM OmsChargerRateEntity ")
	Integer selectNewSchemaNo();

	List<OmsChargerRateEntity> findByRateSchemaAndSerialNoNotIn(Integer rateSchema, List<Integer> serialNos);

	@Query(" SELECT count(*) FROM OmsChargerRateEntity WHERE rate_name = :rateName  and rate_schema <> :rateSchema ")
	Integer getSumByRateNameAndRateSchema(@Param("rateName") String rateName, @Param("rateSchema") Integer rateSchema);

	@Query(" SELECT count(*) FROM OmsChargerRateEntity WHERE default_for = :defaultFor AND rate_schema <> :rateSchema AND default_ind = 1 AND fee_type = :feeType ")
	Integer getSumByDefaultIndAndDefaultForAndRateSchemaAndFeeType(@Param("defaultFor") String defaultFor, @Param("rateSchema") Integer rateSchema, @Param("feeType") Integer feeType);

	List<OmsChargerRateEntity> findByDefaultIndAndValidFlagAndDefaultForInOrderByDefaultForDesc(Integer DefaultInd, Integer validFlag, List<String> defaultFor);
}